package com.openbravo.data.loader;

import com.openbravo.basic.BasicException;
import java.awt.image.BufferedImage;
import java.text.DateFormat;
import java.text.SimpleDateFormat;
import java.util.Date;

public abstract class Datas
{
  public static final Datas INT = new DatasINT( );
  public static final Datas STRING = new DatasSTRING( );
  public static final Datas DOUBLE = new DatasDOUBLE( );
  public static final Datas BOOLEAN = new DatasBOOLEAN( );
  public static final Datas TIMESTAMP = new DatasTIMESTAMP( );
  public static final Datas BYTES = new DatasBYTES( );
  public static final Datas IMAGE = new DatasIMAGE( );
  public static final Datas OBJECT = new DatasOBJECT( );
  public static final Datas SERIALIZABLE = new DatasSERIALIZABLE( );
  public static final Datas NULL = new DatasNULL( );
  private static DateFormat tsf = new SimpleDateFormat("yyyy-MM-dd HH:mm:ss.SSS");

  public abstract Object getValue(DataRead paramDataRead, int paramInt)
    throws BasicException;

  public abstract void setValue(DataWrite paramDataWrite, int paramInt, Object paramObject)
    throws BasicException;

  public abstract Class getClassValue();

  protected abstract String toStringAbstract(Object paramObject);

  protected abstract int compareAbstract(Object paramObject1, Object paramObject2);

  public String toString(Object paramObject)
  {
    if (paramObject == null)
      return "null";
    return toStringAbstract(paramObject);
  }

  public int compare(Object paramObject1, Object paramObject2)
  {
    if (paramObject1 == null)
    {
      if (paramObject2 == null)
        return 0;
      return -1;
    }
    if (paramObject2 == null)
      return 1;
    return compareAbstract(paramObject1, paramObject2);
  }

  private static final class DatasNULL extends Datas
  {
    private DatasNULL()
    {
      super();
    }

    public Object getValue(DataRead paramDataRead, int paramInt)
      throws BasicException
    {
      return null;
    }

    public void setValue(DataWrite paramDataWrite, int paramInt, Object paramObject)
      throws BasicException
    {
    }

    public Class getClassValue()
    {
      return Object.class;
    }

    protected String toStringAbstract(Object paramObject)
    {
      return "null";
    }

    protected int compareAbstract(Object paramObject1, Object paramObject2)
    {
      throw new UnsupportedOperationException();
    }
  }

  private static final class DatasSERIALIZABLE extends Datas
  {
    private DatasSERIALIZABLE()
    {
      super();
    }

    public Object getValue(DataRead paramDataRead, int paramInt)
      throws BasicException
    {
      return ImageUtils.readSerializable(paramDataRead.getBytes(paramInt));
    }

    public void setValue(DataWrite paramDataWrite, int paramInt, Object paramObject)
      throws BasicException
    {
      paramDataWrite.setBytes(paramInt, ImageUtils.writeSerializable(paramObject));
    }

    public Class getClassValue()
    {
      return Object.class;
    }

    protected String toStringAbstract(Object paramObject)
    {
      return "0x" + ImageUtils.bytes2hex(ImageUtils.writeSerializable(paramObject));
    }

    protected int compareAbstract(Object paramObject1, Object paramObject2)
    {
      throw new UnsupportedOperationException();
    }
  }

  private static final class DatasOBJECT extends Datas
  {
    private DatasOBJECT()
    {
      super();
    }

    public Object getValue(DataRead paramDataRead, int paramInt)
      throws BasicException
    {
      return paramDataRead.getObject(paramInt);
    }

    public void setValue(DataWrite paramDataWrite, int paramInt, Object paramObject)
      throws BasicException
    {
      paramDataWrite.setObject(paramInt, paramObject);
    }

    public Class getClassValue()
    {
      return Object.class;
    }

    protected String toStringAbstract(Object paramObject)
    {
      return "0x" + ImageUtils.bytes2hex(ImageUtils.writeSerializable(paramObject));
    }

    protected int compareAbstract(Object paramObject1, Object paramObject2)
    {
      throw new UnsupportedOperationException();
    }
  }

  private static final class DatasIMAGE extends Datas
  {
    private DatasIMAGE()
    {
      super();
    }

    public Object getValue(DataRead paramDataRead, int paramInt)
      throws BasicException
    {
      return ImageUtils.readImage(paramDataRead.getBytes(paramInt));
    }

    public void setValue(DataWrite paramDataWrite, int paramInt, Object paramObject)
      throws BasicException
    {
      paramDataWrite.setBytes(paramInt, ImageUtils.writeImage((BufferedImage)paramObject));
    }

    public Class getClassValue()
    {
      return BufferedImage.class;
    }

    protected String toStringAbstract(Object paramObject)
    {
      return "0x" + ImageUtils.bytes2hex(ImageUtils.writeImage((BufferedImage)paramObject));
    }

    protected int compareAbstract(Object paramObject1, Object paramObject2)
    {
      throw new UnsupportedOperationException();
    }
  }

  private static final class DatasBYTES extends Datas
  {
    private DatasBYTES()
    {
      super();
    }

    public Object getValue(DataRead paramDataRead, int paramInt)
      throws BasicException
    {
      return paramDataRead.getBytes(paramInt);
    }

    public void setValue(DataWrite paramDataWrite, int paramInt, Object paramObject)
      throws BasicException
    {
      paramDataWrite.setBytes(paramInt, (byte[])(byte[])paramObject);
    }

    public Class getClassValue()
    {
     // return [B.class;
    	return Byte.class;
    }

    protected String toStringAbstract(Object paramObject)
    {
      return "0x" + ImageUtils.bytes2hex((byte[])(byte[])paramObject);
    }

    protected int compareAbstract(Object paramObject1, Object paramObject2)
    {
      throw new UnsupportedOperationException();
    }
  }

  private static final class DatasTIMESTAMP extends Datas
  {
    private DatasTIMESTAMP()
    {
      super();
    }

    public Object getValue(DataRead paramDataRead, int paramInt)
      throws BasicException
    {
      return paramDataRead.getTimestamp(paramInt);
    }

    public void setValue(DataWrite paramDataWrite, int paramInt, Object paramObject)
      throws BasicException
    {
      paramDataWrite.setTimestamp(paramInt, (Date)paramObject);
    }

    public Class getClassValue()
    {
      return Date.class;
    }

    protected String toStringAbstract(Object paramObject)
    {
      return Datas.tsf.format(paramObject);
    }

    protected int compareAbstract(Object paramObject1, Object paramObject2)
    {
      return ((Date)paramObject1).compareTo((Date)paramObject2);
    }
  }

  private static final class DatasBOOLEAN extends Datas
  {
    private DatasBOOLEAN()
    {
      super();
    }

    public Object getValue(DataRead paramDataRead, int paramInt)
      throws BasicException
    {
      return paramDataRead.getBoolean(paramInt);
    }

    public void setValue(DataWrite paramDataWrite, int paramInt, Object paramObject)
      throws BasicException
    {
      paramDataWrite.setBoolean(paramInt, (Boolean)paramObject);
    }

    public Class getClassValue()
    {
      return Boolean.class;
    }

    protected String toStringAbstract(Object paramObject)
    {
      return ((Boolean)paramObject).toString();
    }

    protected int compareAbstract(Object paramObject1, Object paramObject2)
    {
      return ((Boolean)paramObject1).compareTo((Boolean)paramObject2);
    }
  }

  private static final class DatasDOUBLE extends Datas
  {
    private DatasDOUBLE()
    {
      super();
    }

    public Object getValue(DataRead paramDataRead, int paramInt)
      throws BasicException
    {
      return paramDataRead.getDouble(paramInt);
    }

    public void setValue(DataWrite paramDataWrite, int paramInt, Object paramObject)
      throws BasicException
    {
      paramDataWrite.setDouble(paramInt, (Double)paramObject);
    }

    public Class getClassValue()
    {
      return Double.class;
    }

    protected String toStringAbstract(Object paramObject)
    {
      return ((Double)paramObject).toString();
    }

    protected int compareAbstract(Object paramObject1, Object paramObject2)
    {
      return ((Double)paramObject1).compareTo((Double)paramObject2);
    }
  }

  private static final class DatasSTRING extends Datas
  {
    private DatasSTRING()
    {
      super();
    }

    public Object getValue(DataRead paramDataRead, int paramInt)
      throws BasicException
    {
      return paramDataRead.getString(paramInt);
    }

    public void setValue(DataWrite paramDataWrite, int paramInt, Object paramObject)
      throws BasicException
    {
      paramDataWrite.setString(paramInt, (String)paramObject);
    }

    public Class getClassValue()
    {
      return String.class;
    }

    protected String toStringAbstract(Object paramObject)
    {
      return "'" + DataWriteUtils.getEscaped((String)paramObject) + "'";
    }

    protected int compareAbstract(Object paramObject1, Object paramObject2)
    {
      return ((String)paramObject1).compareTo((String)paramObject2);
    }
  }

  private static final class DatasINT extends Datas
  {
    private DatasINT()
    {
      super();
    }

    public Object getValue(DataRead paramDataRead, int paramInt)
      throws BasicException
    {
      return paramDataRead.getInt(paramInt);
    }

    public void setValue(DataWrite paramDataWrite, int paramInt, Object paramObject)
      throws BasicException
    {
      paramDataWrite.setInt(paramInt, (Integer)paramObject);
    }

    public Class getClassValue()
    {
      return Integer.class;
    }

    protected String toStringAbstract(Object paramObject)
    {
      return ((Integer)paramObject).toString();
    }

    protected int compareAbstract(Object paramObject1, Object paramObject2)
    {
      return ((Integer)paramObject1).compareTo((Integer)paramObject2);
    }
  }
}

/* Location:           D:\PowerFulPOS-2.30.2\openbravopos.jar
 * Qualified Name:     com.openbravo.data.loader.Datas
 * JD-Core Version:    0.6.0
 */